package com.lock.demo.zookeeper.test;

import com.lock.demo.config.ApplicationContextProvider;
import com.lock.demo.redis.lock.RedisLock;
import com.lock.demo.zookeeper.lock.ZKLock;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;

import java.util.concurrent.TimeUnit;

/**
 * @ProjectName: lock_demo
 * @Package: com.lock.demo.mysql.test
 * @Author: huat
 * @Date: 2021/5/4 15:37
 * @Version: 1.0
 */
@Slf4j
public class StockService implements Runnable{
    ZKLock zkLock;
    //实际开发中可以不使用构造函数注入
    public StockService() {

        zkLock=new ZKLock("127.0.0.1:2181","lock_name");

    }

    @Override
        public void run() {

        zkLock.lock();
        boolean flag=new Stock().reduceStock();

        zkLock.unlock();

        if(flag){
            log.info(Thread.currentThread().getName()+"减少成功");
        }else{
            log.info(Thread.currentThread().getName()+"减少失败");
        }
    }


}
